package com.hualan.controller;

import com.hualan.domain.Consultreply;
import com.hualan.domain.User;
import com.hualan.service.ConsultReplyService;
import com.hualan.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/consultReply")
public class ConsultReplyController {
    @Autowired
    public ConsultReplyService consultReplyService;

    @GetMapping("/reply/show")
    public R selectAllreply(){
        List<Consultreply> consultreplyList = consultReplyService.selectAllreply();
        if (consultreplyList==null){
            return R.fail(200);
        }else {
            return R.success(consultreplyList);
        }
    }

    @GetMapping("/reply/like")
    public R selectAlllike(String replytext){
        List<Consultreply> consultreplyList = consultReplyService.selectAlllike(replytext);
        if (consultreplyList==null){
            return R.fail(200);
        }else {
            return R.success(consultreplyList);
        }
    }

    @PostMapping("/reply/insert")
    public R insertSelective(Consultreply record){
        int  i = consultReplyService.insertSelective(record);
        if(i>0){
            return R.success(i);
        }else{
            return R.fail(i);
        }
    }

    @PutMapping("/reply/update")
    public R updateReply(Consultreply consultreply){
        int i= consultReplyService.updateReply(consultreply);
        if(i>0){
            return R.success(i);
        }else{
            return R.fail(i);
        }
    }

    @DeleteMapping("/reply/delete")
    public R deleteByPrimaryKey(Long id){
        int i = consultReplyService.deleteByPrimaryKey(id);
        if(i>0){
            return R.success(i);
        }else{
            return R.fail(i);
        }
    }

    @GetMapping("/Reply/selectUseridUsername")
    public R selectAllUserIdUserName(){
        List<User> userList= consultReplyService.selectAllUserIdUserName();
        if (userList==null){
            return R.fail(200);
        }else {
            return R.success(userList);
        }
    }
}
